package com.edu.entity;

import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 产品
 *
 * 数据规则:
 *  1. 非空数据
 *  2. 收益率 0 - 30
 *  3. 投资步长 为整数
 *
 */
@Entity
@Table(name = "t_product")
@Data
public class Product {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name ="id", columnDefinition = "bigint COMMENT '主键，自动递增生成'")
    private Long id;


    @NotNull
    @Column(name ="name", nullable = false, columnDefinition = "varchar(64) COMMENT '产品名称'")
    private String name;

    @NotNull
    @Column(name ="status", nullable = false, columnDefinition = "varchar(64) COMMENT '产品状态：AUDITING审核中,IN_SELL销售中;LOCKED已锁定,FINISH已完成'")
    private String status;

    /* 起投金额 */
    @NotNull
    @Column(name ="threshold_amount", nullable = false, columnDefinition = "decimal(15,3) COMMENT '起投金额'")
    private BigDecimal thresholdAmount;

    /* 投资步长 */
    @NotNull
    @Column(name ="step_amount", nullable = false, columnDefinition = "decimal(15,3) COMMENT '投资步长'")
    private BigDecimal stepAmount;

    @NotNull
    @Column(name ="lock_term", nullable = false, columnDefinition = "int COMMENT '锁定期，单位：天'")
    private Integer lockTerm;
    /* 收益率 */
    @Min(0)
    @Max(30)
    @Column(name ="reward_rate", nullable = false, columnDefinition = "decimal(5,3) COMMENT '收益率：0-100'")
    private BigDecimal rewardRate;

    @Column(name ="memo", columnDefinition = "varchar(255) COMMENT '备注'")
    private String memo;

    @CreationTimestamp
    @Column(name ="create_at", columnDefinition = "datetime COMMENT '创建时间'")
    private Date createAt;

    @Column(name ="create_user", columnDefinition = "varchar(64) COMMENT '创建人'")
    private String createUser;

    @UpdateTimestamp
    @Column(name ="update_at", columnDefinition = "datetime COMMENT '更新时间'")
    private Date updateAt;

    @Column(name ="update_user", columnDefinition = "varchar(64) COMMENT '更新人'")
    private String updateUser;

}
